﻿using System.IO;

namespace Com.OpenCode.DwgConvert.Model
{
    /// <summary>
    /// 任务数据源
    /// 输入输出通用
    /// </summary>
    public class TaskDatasource
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="source"></param>
        public TaskDatasource(string source)
        {
            this.Source = source;
            if (string.IsNullOrEmpty(Source))
            {
                SourceType = SourceType.UnKnow;
            }
            if (File.Exists(Source))
            {
                SourceType = SourceType.File;
                FileInfo fileInfo = new FileInfo(Source);
                Name = fileInfo.Name.Substring(0, fileInfo.Name.LastIndexOf(fileInfo.Extension));
            }
            else if (Directory.Exists(Source))
            {
                SourceType = SourceType.Directory;
                DirectoryInfo directoryInfo = new DirectoryInfo(Source);
                Name = directoryInfo.Name;
            }
            else
            {
                SourceType = SourceType.UnKnow;
            }
        }

        /// <summary>
        /// 输入或输出的数据源位置
        /// </summary>
        public string Source { get; set; }

        /// <summary>
        /// 获取或设置文件或文件夹的名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 数据源类型
        /// 文件或目录
        /// </summary>
        public SourceType SourceType { get; set; }

        /// <summary>
        /// 数据源中数据数量
        /// </summary>
        public long Count { get; set; }
    }
}